//
//  ByBallBetInfoCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/15.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBallBetInfoCell.h"
#import "ByBetRecordTitleView.h"
#import "ByBetTitleValueView.h"
#import "ByBallBetDetailView.h"


@implementation ByBallBetInfoCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByBallBetInfoCell";
    ByBallBetInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
    }
    return self;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    [self initViews];
}

- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    
    ByBetRecordTitleView *titleView = [[ByBetRecordTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@50);
    }];
    titleView.titleLabel.text = @"投注信息";
    
    UILabel *stateLabel = [[UILabel alloc] init];
    [backgroundView addSubview:stateLabel];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(10);
        make.right.equalTo(backgroundView).offset(-10);
        make.top.equalTo(titleView.mas_bottom).offset(10);
        make.height.mas_equalTo(@20);
    }];
    stateLabel.textColor = [UIColor blackColor];
    stateLabel.text = @"出票中";
    stateLabel.font = B_FONT(16);
    self.stateLabel = stateLabel;
    
//    if (_netModel.pay_status.integerValue == 0) {
//
//
//        self.stateLabel.text = @"未支付";
//
//
//    }else if (_netModel.pay_status.integerValue == 1){
//
//        if (_netModel.status.integerValue == -1) {
//            stateLabel.text = @"已过期";
//        }else if (_netModel.status.integerValue == 0){
//            stateLabel.text = @"未出票";
//        }else if (_netModel.status.integerValue == 1){
//            stateLabel.text = @"出票中";
//        }else if (_netModel.status.integerValue == 2){
//            stateLabel.text = @"出票成功";
//
//            if (_netModel.is_prize.integerValue == 0) {
//                stateLabel.text = @"未开奖";
//            }else if (_netModel.is_prize.integerValue == 1){
//
//                stateLabel.text = [NSString stringWithFormat:@"已中奖！%@元", _netModel.prize_money];
//                stateLabel.textColor = BY_THEME_COLOR;
//            }else if (_netModel.is_prize.integerValue == 2){
//                stateLabel.text = @"未中奖";
//            }
//
//        }else if (_netModel.status.integerValue == 3){
//            stateLabel.text = @"出票失败";
//        }
//
//    }else if (_netModel.pay_status.integerValue == 2){
//        self.stateLabel.text = @"交易关闭";
//
//    }
    
    if (_netModel.is_prize.integerValue == 1){
        
        stateLabel.text = [NSString stringWithFormat:@"已中奖%.2f元",_netModel.prize_money.floatValue];
        stateLabel.textColor = BY_THEME_COLOR;
        
    }else {
        stateLabel.text = _netModel.status;
    }
  
    
    CGFloat top = 105;
    CGFloat height = 40 + self.netModel.dataArray.count * Table_Height;
    ByBallBetDetailView *detailView = [[ByBallBetDetailView alloc] init];
    [backgroundView addSubview:detailView];
    [detailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView).offset(top);
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@(height));
    }];
    top = top + height + 10;
    detailView.itemsArray = [_netModel.dataArray copy];
    detailView.type = _netModel.name;
    
    for (int i = 0; i < 7; i++) {
        ByBetTitleValueView *valueView = [[ByBetTitleValueView alloc] init];
        [backgroundView addSubview:valueView];
        [valueView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(0);
            make.right.equalTo(backgroundView).offset(0);
            make.top.equalTo(backgroundView).offset(top + i * 30);
            make.height.mas_equalTo(@30);
        }];
        
        if (i == 0) {
            valueView.titleLabel.text = @"开奖时间:";
            if (_netModel.date) {
                 valueView.valueLabel.text = [NSString stringWithFormat:@"预计%@ %@开奖", _netModel.date,_netModel.time];
            }
           
        }else if (i == 1){
            
            valueView.titleLabel.text = @"过关方式:";
            valueView.valueLabel.text = _netModel.play_game;
        }
        else if (i == 2){
            valueView.titleLabel.text = @"投注方式:";
            valueView.valueLabel.text = [NSString stringWithFormat:@"%@注 %@倍",_netModel.bet_num,_netModel.multiple];
        }else if (i == 3){
            valueView.titleLabel.text = @"投注金额:";
            valueView.valueLabel.text = [NSString stringWithFormat:@"%@元", _netModel.amount];
        }else if (i == 4){
            valueView.titleLabel.text = @"投注时间:";
            valueView.valueLabel.text = [NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:_netModel.add_time.integerValue]];
        }else if (i == 5){
            valueView.titleLabel.text = @"投注编号:";
            valueView.valueLabel.text = _netModel.sn;
        }else if (i == 6){
            
            valueView.titleLabel.text = @"加奖:";
            valueView.valueLabel.text = [NSString stringWithFormat:@"%@元", _netModel.bonus];
            
            
        }
    }
    
    
}


@end
